package com.goldenautumn.prefabricate.activity.splash

import com.blankj.utilcode.util.LanguageUtils
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.databinding.ActivityProtocolBinding
import com.goldenautumn.prefabricate.utils.Constants.PROTOCOL_PRIVACY
import com.gyf.immersionbar.ImmersionBar
import kotlinx.coroutines.isActive
import qncx.external.common.base.BaseActivity
import qncx.external.common.constants.Intents.START_ACTIVITY_PARAMS

class ProtocolActivity : BaseActivity<ActivityProtocolBinding>() {


    override fun getLayoutId(): Int = R.layout.activity_protocol

    override suspend fun main() {
        ImmersionBar.setTitleBar(this, mBinding.protocolToolbar)
        initToolbarNav(mBinding.protocolToolbar)

        var type = intent.getStringExtra(PROTOCOL_PRIVACY)
        if(type.isNullOrEmpty()){
            var bundle = intent.extras
            type = bundle?.getString(START_ACTIVITY_PARAMS)
        }
        mBinding.protocolTitle.text = type
        var arr = resources.getStringArray(R.array.user_agreement)
        var language = if(LanguageUtils.isAppliedLanguage()) LanguageUtils.getAppliedLanguage() else LanguageUtils.getSystemLanguage()
        var country = if(language.language == "zh") "${language.language}-${language.country.lowercase()}" else language.language
        if(arr[1] == type) mBinding.webView.loadUrl("http://app.gwdrugs.com/yhxy.html?language=${country}")
        else mBinding.webView.loadUrl("http://app.gwdrugs.com/yszc.html?language=${country}")



        while (isActive) {
            events.receive()
        }
    }

}